home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / timedat.exe / TIMEDATE.DOC < prev    next >
Text File  |  1992-05-09  |  4KB  |  116 lines

  1.  
  2. TIME...
  3.  
  4. I've been teaching my self C++.  And while all the standard
  5. texts keep rambling on about polymorphism, inheritance, virtual
  6. functions and the like, I've gotten the most benefits from
  7. simple encapsulation and operator overloading.
  8.  
  9. They reduce my repeated and visible code, and this helps reduce
  10. errors, reduce production time, and reduce repair time.
  11.  
  12. ------------------------------------------------------------
  13. If you had to compare two timedate pairs to see if they were
  14. equal, which method would you choose?
  15.  
  16. This one...
  17.  
  18.         if ( (td1.year==td2.year) &&
  19.              (td1.month==td2.month) &&
  20.              (td1.day==td2.day)     &&
  21.              (td1.hour==td2.hour)   &&
  22.              (td1.min==td2.min)     &&
  23.              (td1.sec==td2.sec)       )
  24.              printf("Equal\n");
  25.  
  26. Or this one...
  27.  
  28.         if (td1==td2)
  29.              printf("Equal\n");
  30.  
  31. ------------------------------------------------------------
  32. If you had to compare two timedate pairs to verify that a
  33. process starting time entered by a user is before the
  34. process ending   time entered by a user, which method would
  35. you choose?
  36.  
  37. This one...
  38.  
  39.    if ( (td1.year<td2.year) ||
  40.         ((td1.year==td2.year) && (td1.month<td2.month)) ||
  41.         ((td1.year==td2.year)&&(td1.month==td2.month)&&(td1.day<td2.day)) ||
  42.         ((td1.year==td2.year)&&(td1.month==td2.month)&&(td1.day==td2.day)&&
  43.                                                      (td1.hour<td2.hour)) ||
  44.         ((td1.year==td2.year)&&(td1.month==td2.month)&&(td1.day==td2.day)&&
  45.                                  (td1.hour==td2.hour)&&(td1.min<td2.min)) ||
  46.         ((td1.year==td2.year)&&(td1.month==td2.month)&&(td1.day==td2.day)&&
  47.               (td1.hour==td2.hour)&&(td1.min==td2.min)&&(td1.sec<td2.sec)) )
  48.       printf("Good Times\n");
  49.    else
  50.       printf("Bad Times\n");
  51.  
  52.  
  53. Or this one...
  54.  
  55.         if (td_begin<td_end) printf("Good Times\n");
  56.         else                 printf("Bad Times\n");
  57.  
  58. ------------------------------------------------------------
  59. It became obvious after a little examination that one class
  60. would not do the job, because we are dealing with two
  61. fundamentally different concepts.
  62.  
  63.   Points IN Time     and     Spans OF Time
  64.  
  65. Some operations that can be performed on one type of object,
  66. make no sense when applied to the other type of object.
  67.  
  68. If a project consists of two processes "A" and "B".
  69. And the time to complete phase "A" is 2 days and the time
  70. to complete phase "B" is 3 days.  Then the time to complete
  71. the entire project is 2days + 3days = 5days.
  72.  
  73. But, following the same operation, you can't add two POINTS
  74. in time together.   (You can't add 1492 when Columbus discovered
  75. the new world to July 4th, 1776 and get the war of 1812.  Adding
  76. POINTS in time is a senseless operation.)
  77.  
  78. On the other hand, SPANS of time CAN be added to a POINT in time.
  79. (If today is May 6th, 1992, then 2 days from now is
  80.   5/6/92 + 2days = 5/8/92.  So a POINT plus a SPAN equals another
  81.   later POINT in time.)
  82.  
  83. There are several combinations and several exclusions, you'll
  84. just have to read through the operator overloading list
  85. and the demo, and think about what operations are sensible.
  86.  
  87. ------------------------------------------------------------
  88.  
  89. DEMO.CPP      tests and demonstrates all the operator overloading
  90.               possibilities in the timepoint and timespan classes.
  91.  
  92. TIMPOINT.CPP  is a class for defining and manipulating
  93.               "Points IN Time"
  94. TIMPOINT.H    is a declaration file for TIMPOINT.CPP
  95.  
  96. TIMESPAN.CPP  is a class for defining and manipulating
  97.               "Spans OF Time"
  98. TIMESPAN.H    is a declaration file for TIMESPAN.CPP
  99.  
  100.  
  101. You get what you pay for, and this code for nothing, so, there
  102. are no guarantees.  It works for me but, it's up to you to use
  103. the code enclosed responsibly and correctly.
  104.  
  105. I offer the code to the public domain for all to use with no
  106. royalties or costs.  Pass it on to anyone that wants it.
  107.  
  108. If you have any suggestions or comments please E-Mail me at
  109.  
  110. John K. Humkey
  111. CompuServe: [73270,3166]
  112. INTERNET:   73270.3166@compuserve.com
  113.  
  114. GOOD LUCK!
  115.  
  116.